/*
 * Copyright (C) 2012 Le Tuan Anh <anh.takaji@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ezcms.dal.hibernate.mysql;

import ezcms.dal.SubmissionDAO;
import ezcms.dto.ConferenceItemSubmission;
import ezcms.exceptions.DataLayerException;
import java.util.List;

/**
 *
 * @author Le Tuan Anh <anh.takaji@gmail.com>
 */
class SubmissionDAOImpl implements SubmissionDAO {

    public SubmissionDAOImpl() {
    }

    @Override
    public List<ConferenceItemSubmission> getAllConferenceItemSubmissions() throws DataLayerException {
        return HibernateUtil.getListByConditions(ConferenceItemSubmission.class, null, "Cannot retrieve all ConferenceItemSubmissions");
    }

    @Override
    public ConferenceItemSubmission getConferenceItemSubmissionById(long id) throws DataLayerException {
        Object result = HibernateUtil.getObjectById(ConferenceItemSubmission.class, id, "Cannot find ConferenceItemSubmission object with id = " + id);
        return (result == null) ? null : (ConferenceItemSubmission) result;
    }

    @Override
    public void saveConferenceItemSubmission(ConferenceItemSubmission conferenceItemSubmission) throws DataLayerException {
        if (conferenceItemSubmission == null) {
            throw new DataLayerException("submission must not be null");
        }
        else if(!conferenceItemSubmission.isValid()){
            throw new DataLayerException("Invalid submission");
        }
        HibernateUtil.saveObject(conferenceItemSubmission, "Cannot save ConferenceItemSubmission");
    }

    @Override
    public void deleteConferenceItemSubmission(ConferenceItemSubmission conferenceItemSubmission) throws DataLayerException {
        HibernateUtil.deleteObject(conferenceItemSubmission, "Cannot delete ConferenceItemSubmission");
    }
}
